--- title: "抓娃娃" created: 2025-11-28 tags: - 算法 --- # 抓娃娃 ## 题目 [抓娃娃](https://www.lanqiao.cn/problems/17110/learning/) ![[image-55d952c9.png]] ## 思路分析 ## 代码实现 ```cpp #include using namespace std; #define endl '\n' //还有1h45m 把剩余题都看一下 估计只能干出一道来了 //这题 好像能写 但是第九题貌似能骗 先写第九题 //9写了 10跳了 还有1h13m //暴力肯定能做 但想找一下优化的点 //先是n条线段 再是m条查询区间 //问这m条区间分别框住了多少个线段(达到一半就算框住) //直接先想暴力吧 /* 如何判断某个区间被框住 区间首先全都按左端点排序 大概分为以下几种情况 sl---sr 中点sm shl ql-----qr 若ql小于等于sl 则只有qr>=sm时 才能包含 若ql大于等于sl 且 小于等于 sm时 则只有 qr>=ql+shl才能包含 若ql大于 sm 则直接不可能 所以对于每条线段 要存储它的 左端点 中点 以及一半长度 即sl,sm,shl 而对于每个区间 只需要存左端和右端即可 */ typedef pair PDD; struct seg{ double sl; double sm; double shl; bool operator<(const seg& other)const{ return sl segs; vector query; int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int n,m; cin>>n>>m; for(int i=0;i>l>>r; double sl=l,sm=(l+r)*1.0/2,shl=(r-l)*1.0/2; segs.push_back({sl,sm,shl}); } sort(segs.begin(),segs.end()); // for(auto x:segs) cout<>l>>r; query.push_back({l,r}); } // for(auto x:query) cout<=sl && ql<=sm && qrsm) continue; cnt++; } cout<